#include <iostream>
using std::cout;
using std::endl;

class Point
{
public:
    Point()
    : _ix(0)
    , _iy(0)
    {
        cout << "Point()" << endl;
    }

    Point(int x,int y = 1)
    : _ix(x)
    , _iy(y)
    {
        cout << "Point(int,int)" << endl;
    }

    Point(const Point & rhs)
    : _ix(rhs._ix)
    , _iy(rhs._iy)
    {
        cout << "拷贝构造" << endl;
    }

    //Point * const this;
    //不用显式地在函数参数列表中写出this指针
    Point & operator=(const Point & rhs){
        cout << "赋值运算符函数" << endl;
        this->_ix = rhs._ix;
        this->_iy = rhs._iy;
        //哪个对象调用这个函数
        //就返回这个对象
        return *this;
    }

    //对象调用成员函数时
    //编译器会记录这个对象的地址（this指针）
    //让this指针作为该成员函数的第一个参数
    void print(){
        //this指针不能修改指向，一定保存的是“本对象”的地址
        /* &this; */
        /* this = new Point(0,0);//error */
        /* this->_ix = 100;//ok */
        cout << "(" << this->_ix
            << "," << this->_iy
            << ")" << endl;
    }
private:
    int _ix;
    int _iy;
};

void test0(){
    /* int x = 10; */
    /* int y = x; */
    /* cout << y << endl; */

    /* Point pt(30,50); */
    /* Point pt2 = pt; */
    /* pt2.print(); */

    int x = 10;
    int y = 20;
    cout << &(x = y) << endl;
    cout << &x << endl;

    Point pt(2,7);
    Point pt2(8,9);
    pt.print();
    pt2.print();
    cout << endl;

    /* //operator+ */
    /* pt + pt2; */

    pt = pt2;//赋值
    /* pt.operator=(pt2);//本质形式 */
    pt.print();
}

int main(void){
    test0();
    return 0;
}
